package com.zhang.controller;


import com.zhang.service.ShoppingProductService;
import com.zhang.units.Result;
import com.zhang.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@RestController
@RequestMapping("/shopping-product")
public class ShoppingProductController {

    @Autowired
    private ShoppingProductService shoppingProductService;

    /**
     * 详细信息
     */
    @GetMapping("/product")
    public Result productById(@RequestParam("productId") int productId){
        return  Result.result200(shoppingProductService.selectShoppingProductByProductId(productId));
    }
    /**
     * 新增商品
     */
    @PostMapping("add_product")
    public  Result addProduct(@RequestBody ProductVo productVo){
        return Result.result500(shoppingProductService.addProduct(productVo));
    }
    /**
     * 修改商品
     */
    @PostMapping("update_product")
    public  Result updateProduct(@RequestBody ProductVo productVo){
        return Result.result500(shoppingProductService.updateProduct(productVo));
    }
    /**
     * 删除商品
     */
    @GetMapping("/delete_product")
    public  Result deleteProduct1(@RequestParam("productId") String productId){
        return Result.result200(shoppingProductService.removeById(productId));
    }
    /**
     * 删除二级类目
     */
    @GetMapping("/delete_product2")
    public  Result deleteProduct2(@RequestParam("productIds") List<String> productIds){
        return Result.result200(shoppingProductService.removeByIds(productIds));
    }
}

